package com.eBook.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eBook.entity.Prize;
import com.eBook.service.PrizeService;

@Controller
@RequestMapping("/prize")
public class PrizeController {

	@Autowired
	PrizeService prizeService;
	
	/**
	 * 找到所有奖品
	 * @return
	 */
	@RequestMapping(value="/", method=RequestMethod.GET)
	@ResponseBody
	public List<Prize> findAllPrize(){
		return prizeService.findAllPrize();
	}
	
	/**
	 * 返回兑换奖品后的剩余数量
	 * @param prizeId
	 * @param prizeNum
	 * @return
	 */
	@RequestMapping(value="/{prizeId}/{reduceNum}", method=RequestMethod.GET)
	@ResponseBody
	public String reducePrizeNum(
			@PathVariable("prizeId")Integer prizeId,
			@PathVariable("reduceNum")Integer prizeNum){
		int num = prizeService.reducePrizeNum(prizeId, prizeNum);
		return "" + num;
	}
}
